<template>
	<div class="home" @scroll="handleScroll()">
		<!-- 头部 -->
		<div class="header">
			<router-link  to="/home"><img src="http://i.huasongwang.com/i/logo/mhuayu.jpg" alt="" /></router-link>
			<router-link  to="/sort">
				<div class="input">
					<span></span>
					<p>搜索产品</p>
				</div>
			</router-link>
			<router-link  to="/myIndex"><p class="loginBtn">{{loginStatus?'我的':'登录'}}</p></router-link>
		</div>

		<!-- 头部显隐导航 -->
		<ul v-show="scrollTop > 100" class="header-sh">
			<router-link  to="/sort"><li>爱情鲜花</li></router-link>
			<router-link  to="/sort"><li>生日鲜花</li></router-link>
			<router-link  to="/sort"><li>开业花篮</li></router-link>
			<router-link  to="/sort"><li>绿植专区</li></router-link>
		</ul>

		<!-- 轮播图 -->
		<div class="banner"><Carrousel :swiperImg="swiperImg"></Carrousel></div>
		
		<!-- 内容 -->
		<div class="content">
			<!-- 文字广告 -->
			<ul class="textAdvertisement">
				<router-link  to="/sort">
					<li>
						<span class="icon-flower1"></span>
						<p>优质鲜花花村</p>
					</li>
				</router-link>
				<router-link  to="/sort">
					<li>
						<span class="icon-flower2"></span>
						<p>12年知名品牌</p>
					</li>
				</router-link>
				<router-link  to="/sort">
					<li>
						<span class="icon-flower3"></span>
						<p>高效鲜花遍递</p>
					</li>
				</router-link>
			</ul>

			<!-- 入口 -->
			<ul class="inlet">
				<li class="inlet-list" v-for="inlet in inletList" :key="inlet.index">
					<router-link  to="/sort"><InletSub :inlets="inlet"></InletSub></router-link>
				</li>
			</ul>

			<!-- 过度广告图 -->
			<div class="adv-img">
				<router-link  to="/sort"><img src="http://i.huasongwang.com/i/c/tejia.png" alt="" /></router-link>
			</div>

			<!-- 快捷选择 -->
			<div class="quick-box">
				<h6>-快捷选择-</h6>
				<ul class="quick">
					<router-link  to="/sort"><img src="http://i.huasongwang.com/i/c/hs11.png" alt="" /></router-link>
					<router-link  to="/sort"><img src="http://i.huasongwang.com/i/c/hs12.png" alt="" /></router-link>
					<router-link  to="/sort"><img src="http://i.huasongwang.com/i/c/hs13.png" alt="" /></router-link>
					<router-link  to="/sort"><img src="http://i.huasongwang.com/i/c/hs14.png" alt="" /></router-link>
				</ul>
			</div>

			<!-- 人气推荐 -->
			<div class="recommend-box">
				<div class="recommend-title">
					<h6>人气推荐</h6>
					<router-link  to="/sort"><p>更多&gt;</p></router-link>
				</div>
				<ul>
					<li v-for="goods in recList" :key="goods.id">
						<RecommendSub :goods="goods"></RecommendSub>
					</li>
				</ul>
			</div>

			<!-- 鲜花模块 -->
			<div class="type-model" v-for="typeModel in typeModelList" :key="typeModel.index">
				<!-- 模块标题 -->
				<div class="type-title">
					<span></span>
					<h5>{{ typeModel.title }}</h5>
					<span></span>
				</div>
				<!-- 模块分类 -->
				<ul class="type-two">
					<li v-for="navTwo in typeModel.navTwo" :key="navTwo.index">
						<router-link to="/sort">{{ navTwo }}</router-link>
					</li>
				</ul>
				<!-- 模块内容 -->
				<ul class="goods">
					<li v-for="navData in typeModel.navDataList" :key="navData.index">
						<router-link  :to="'/detail?goodsId='+navData.id"><GoodsSub :goods="navData"></GoodsSub></router-link>
					</li>
				</ul>
			</div>

			<!-- 礼品推荐 -->
			<div class="gift-box">
				<div class="recommend-title">
					<h6>礼品推荐</h6>
					<router-link  to="/sort"><p>更多&gt;</p></router-link>
				</div>
				<router-link to="/sort"><img src="http://i.huasongwang.com/i/c/wlping.jpg" alt="" /></router-link>
				<div class="gif-bottom">
					<router-link to="/sort"><img src="http://i.huasongwang.com/i/g/2019/12/11/06293964672804700_360.jpg" alt="" /></router-link>
					<router-link to="/sort"><img src="http://i.huasongwang.com/i/g/2019/12/11/06293976527531060_360.jpg" alt="" /></router-link>
					<router-link to="/sort"><img src="http://i.huasongwang.com/i/g/2019/12/11/06294010682102256_360.jpg" alt="" /></router-link>
				</div>
			</div>
			
			<!-- 底部 -->
			<div class="footer-home"><FooterSub></FooterSub></div>
		</div>

		<!-- 在线客服 -->
		<OnlineService></OnlineService>

		<!-- 返回顶部 -->
			<ToTop v-show="scrollTop >= 45" @clickHandle="backTop()"></ToTop>
		
	</div>
</template>

<script>
import Carrousel from '@/components/carrousel.vue'; //轮播图
import OnlineService from '@/components/onlineService.vue'; //在线客服
import ToTop from '@/components/toTop.vue'; //返回顶部组件
import InletSub from '@/components/inletSub.vue'; //入口组件
import RecommendSub from '@/components/recommendSub.vue'; //人气推荐商品组件
import GoodsSub from '@/components/goodsSub.vue'; //商品组件
import FooterSub from '@/components/footerSub.vue'; //底部

export default {
	name: 'home',
	data() {
		return {
			headerSH: false, //弹出广告
			scrollTop: 0, //滚动条高度
			auto: null, //滚回顶部定时器
			loginStatus:false,
			userInfo:{},
			swiperImg: [
				'http://i.huasongwang.com/i/c/hsong/shengrim.png',
				'http://i.huasongwang.com/i/c/mhualan.jpg',
				'http://i.huasongwang.com/i/c/wapban1.jpg',
				'http://i.huasongwang.com/i/c/wapban2.jpg',
				'http://i.huasongwang.com/i/c/hsong/xingzuo/shizi.jpg'
			],
			inletList: [
				{
					title: '全部鲜花',
					imgPath: 'http://i.huasongwang.com/i/c/hs1.png'
				},
				{
					title: '爱情鲜花',
					imgPath: 'http://i.huasongwang.com/i/c/hs2.png'
				},
				{
					title: '生日鲜花',
					imgPath: 'http://i.huasongwang.com/i/c/hs3.png'
				},
				{
					title: '永生花',
					imgPath: 'http://i.huasongwang.com/i/c/hs4.png'
				},
				{
					title: '蛋糕',
					imgPath: 'http://i.huasongwang.com/i/c/hs5.png'
				},
				{
					title: '礼盒鲜花',
					imgPath: 'http://i.huasongwang.com/i/c/hs6.png'
				},
				{
					title: '开业花篮',
					imgPath: 'http://i.huasongwang.com/i/c/hs7.png'
				},
				{
					title: '绿植',
					imgPath: 'http://i.huasongwang.com/i/c/hs8.png'
				},
				{
					title: '礼品',
					imgPath: 'http://i.huasongwang.com/i/c/hs9.png'
				},
				{
					title: '其他分类',
					imgPath: 'http://i.huasongwang.com/i/c/hs10.png'
				}
			],
			recGoodsList: [1, 2, 3, 4],
			recList: [],
			typeModelList: []
		};
	},
	created() {
		/* 当前登录用户 */
		if(localStorage.getItem("thisUser")){
			this.loginStatus = true;
		}else{
			this.loginStatus = false;
		}
		/* 首页数据 */
		this.axios.get('https://www.fastmock.site/mock/db3aaecafecce7bef237fef166118389/huayu/huayu-home-data').then(res => {
			// console.log(res);
			this.recList = res.recList;
			this.typeModelList = res.typeModelList;
		});
	},
	methods: {
		/* 滚动条 */
		handleScroll() {
			this.scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
			// console.log(this.scrollTop);
		},
		/* 滚动条回到顶部 */
		backTop() {
			if (this.scrollTop > 44) {
				this.auto = setInterval(() => {
					this.scrollTop -= 30;
					if (this.scrollTop <= 0) {
						document.documentElement.scrollTop = 0;
						clearInterval(this.auto);
					} else {
						document.documentElement.scrollTop = this.scrollTop;
					}
				}, 10);
			}
		}
	},
	mounted() {
		// 先给页面注册滚动事件
		window.addEventListener('scroll', this.handleScroll, true);
	},
	beforeDestroy() {
		clearInterval(this.auto);
	},
	destroyed() {
		// 离开该页面需要移除这个监听的事件，不然会报错
		window.removeEventListener('scroll', this.handleScroll);
	},
	components: {
		Carrousel,
		OnlineService,
		ToTop,
		InletSub,
		RecommendSub,
		GoodsSub,
		FooterSub
	}
};
</script>

<style scoped="scoped">
@import url('../css/publice.css');

.home {
	width: 100%;
	/* background-color: #f5f5f5; */
}

/* 头部 */
.header {
	width: 100%;
	height: 1.1rem;
	display: flex;
	justify-content: flex-start;
	align-items: center;
	padding-left: 0;
	position: relative;
}

.header img {
	width: 1.66rem;
	height: 0.88rem;
	position: relative;
}

/* input框 */
.input {
	position: relative;
	left: 0;
	top: 0.03rem;
	width: 4.35rem;
	height: 0.7rem;
	background-color: #f3f3f3;
	border-radius: 0.3rem 0.3rem;
	display: flex;
	align-items: center;
	padding-left: 0.18rem;
}

.input span {
	background: url(../assets/icon5.png) no-repeat -0.06rem -0.05rem;
	width: 0.5rem;
	height: 0.5rem;
	background-size: 2.7rem 1.86rem;
	/* transform: scale(2); */
}

.input p {
	padding-left: 0.3rem;
	font-size: 0.24rem;
}

/* 登录 */
.loginBtn {
	position: absolute;
	right: 0.08rem;
	top: 50%;
	transform: translateY(-51%);
	color: #6666;
	font-size: 0.32rem;
}

/* 头部显隐导航 */
.header-sh {
	width: 100%;
	height: 0.896rem;
	display: flex;
	justify-content: space-around;
	align-items: center;
	background-color: #ee3200;
	position: fixed;
	top: 0;
	z-index: 4;
}

.header-sh li {
	color: white;
	font-size: 0.28rem;
}

/* 内容 */
.content {
	background-color: #f5f5f5;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: center;
	padding: 0 0.01rem;
	margin-bottom: 1.12rem;
}
/* 文字广告 */
.textAdvertisement {
	width: 100%;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0.1rem 0.18rem;
	background-color: white;
	border-bottom: #f5f5f5 solid 0.01rem;
}

.textAdvertisement li {
	height: 0.48rem;
	display: flex;
	align-items: center;
}
.textAdvertisement li p {
	font-size: 0.2rem;
	padding: 0 0.08rem;
}
.textAdvertisement li span {
	position: relative;
	top: 0.05rem;
	width: 21px;
	height: 21px;
	background-image: url(http://i.huasongwang.com/i/c/icon5.png);
	background-size: 120px;
}
.textAdvertisement li .icon-flower1 {
	background-position: -36px -3px;
}
.textAdvertisement li .icon-flower2 {
	background-position: -61px -3px;
}
.textAdvertisement li .icon-flower3 {
	background-position: -80px -3px;
}

/* 入口 */
.inlet {
	width: 100%;
	display: flex;
	flex-wrap: wrap;
	justify-content: space-around;
	background-color: white;
	height: 3.16rem;
	padding-top: 0.05rem;
	padding-left: 0.1rem;
}
.inlet-list {
	width: 1.3236rem;
	height: 1.32rem;
}

/* 过度广告图 */
.adv-img {
	width: 100%;
	background-color: white;
	display: flex;
	justify-content: center;
	padding: 0.1rem 0;
}
.adv-img img {
	width: 7.35rem;
	height: 3.06rem;
}

/* 快捷选择 */
.quick-box {
	background-color: white;
	margin-top: 0.2rem;
	padding-top: 0.4rem;
}
.quick-box h6 {
	width: 100%;
	text-align: center;
	font-size: 0.3rem;
	border: white solid 0.01rem;
	margin-bottom: 0.2rem;
}
.quick {
	width: 100%;
	height: 4.64rem;
	display: flex;
	flex-wrap: wrap;
	justify-content: space-around;
	align-content: space-around;
}
.quick img {
	width: 3.41rem;
	height: 1.92rem;
}

/* 人气推荐 */
.recommend-box {
	background-color: white;
	width: 100%;
	padding: 0.2rem 0;
	padding-bottom: 0.3rem;
	margin-top: 0.2rem;
}
.recommend-title {
	width: 100%;

	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0 0.2rem;
	padding-bottom: 0.4rem;
}
.recommend-title h6 {
	font-size: 0.33rem;
}

/* 爱情鲜花 */
.type-model {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
}

/* 标题 */
.type-title {
	width: 90%;
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin: 0.4rem 0;
}
.type-title h5 {
	width: 60%;
	text-align: center;
	font-size: 0.3rem;
}
.type-title span {
	width: 20%;
	border-bottom: 0.05rem solid #000;
	color: #000;
}
/* 二级标题 */
.type-two {
	width: 100%;
	display: flex;
	justify-content: space-around;
	flex-wrap: wrap;
	align-content: space-around;
}
.type-two li {
	width: 2.34rem;
	height: 0.48rem;
	background-color: white;
	border-radius: 0.5rem;
	text-align: center;
	line-height: 0.48rem;
	margin-bottom: 0.2rem;
}

.goods {
	width: 100%;
	padding-top: 0.4rem;
	display: flex;
	justify-content: space-around;
	flex-wrap: wrap;
	align-content: space-around;
}
.goods li {
	margin-bottom: 0.2rem;
}

/* 礼品推荐 */
.gift-box {
	padding-top: 0.3rem;
	width: 100%;
	background-color: white;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-bottom: 0.2rem;
}
.gift-box img {
	width: 7.06rem;
	height: 2.64rem;
}
.gif-bottom {
	width: 100%;
	display: flex;
	justify-content: space-around;
	align-items: center;
	padding: 0.2rem 0;
}

.gif-bottom img {
	width: 2.2rem;
	height: 2.2rem;
}

.footer-home {
	margin-top: 0.2rem;
}
</style>
